package com.aqarat.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import com.aqarat.entity.Customer;
import com.core.converter.BaseConverter;
import com.core.util.Util;

public class CustomerConverter extends BaseConverter {


	private static final long serialVersionUID = 804153233837781154L;

	public Object getAsObject(FacesContext facesContext, UIComponent uIComponent, String value) {
		Customer result = null;
		if (value == null || (value.trim().length() == 0) || !Util.isNumeric(value)) {
			return "";
		}
		if (value != null && value.trim().length() != 0 && Util.isNumeric(value)) {
			try {
				result = new Customer(Long.valueOf(value.trim()));
			} catch (NumberFormatException e) {
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return result;
	}

	public String getAsString(FacesContext facesContext, UIComponent uIComponent, Object value) {
		if (value instanceof Customer) {
			return Long.toString(((Customer) value).getRecid());
		}
		return null;
	}
}
